package com.yuncheng.spcyApi.controller;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.bo.PartyDfParamBo;
import com.yuncheng.spcyApi.partyService.PartyDfService;
import com.yuncheng.spcyApi.entity.PartyRsDfjnjl;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;

@Api(tags = "党费管理")
@RestController
@RequestMapping("/api/spzx-spcy/partyDf")
public class PartyDfController {

    @Resource
    private PartyDfService partyDfService;

    @Log(title = "党费记录管理-分页查询")
    @ApiOperation(value = "党费记录管理-分页查询")
    @GetMapping(value = "queryDfjlGlPageList")
    public HttpResult<?> queryDfjlGlPageList(PartyRsDfjnjl query, PageVo pageVo, OrderItemVo orderItemVo) {
//        if (StringUtils.isBlank(query.getFjfzt())){
//            query.setFjfzt(SpcyCommonConstant.DF_JNJL_JFZT_DRQ);
//        }
        return partyDfService.queryDfjlPageList(query,pageVo.getPageNo(),pageVo.getPageSize(), orderItemVo);
    }

    @Log(title = "个人党费记录-分页查询")
    @ApiOperation(value = "个人党费记录-分页查询")
    @GetMapping(value = "queryMyDfjlPageList")
    public HttpResult<?> queryMyDfjlPageList(PartyRsDfjnjl query, PageVo pageVo, OrderItemVo orderItemVo) {
        /*if (StringUtils.isBlank(query.getFjfzt())){
            query.setFjfzt(SpcyCommonConstant.DF_JNJL_JFZT_DJF);
        }*/
        query.setFuserid(GetCurrentUserUtils.getCurrentUserId());
        return partyDfService.queryDfjlPageList(query,pageVo.getPageNo(),pageVo.getPageSize(),orderItemVo);
    }

    @Log(title = "党费记录管理-添加/修改")
    @ApiOperation(value = "党费记录管理-添加/修改")
    @PostMapping(value = "saveDfjl")
    public HttpResult saveDfjl(@RequestBody PartyRsDfjnjl bean) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {

        if (StringUtils.isNotBlank(bean.getId())){
            bean = partyDfService.updateDfjl((HashMap<String, String>) BeanUtils.describe(bean));
        }else {
            bean = partyDfService.addDfjl(bean);
        }

        return HttpResultVo.HttpResultSave(bean);
    }

    @Log(title = "党费管理-删除")
    @ApiOperation(value = "党费管理-删除")
    @DeleteMapping(value = "deleteDfjl")
    public HttpResult deleteDfjl(@RequestParam(value = "id",defaultValue = "")String id){
        partyDfService.deleteDfjl(id);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "确认缴费")
    @ApiOperation(value = "确认缴费")
    @PostMapping(value = "confirmPayment")
    public HttpResult confirmPayment(@RequestBody PartyDfParamBo paramBo){
        partyDfService.confirmPayment(paramBo);

        return HttpResult.ok("操作成功");
    }

    @Log(title = "退回待缴费")
    @ApiOperation(value = "退回待缴费")
    @DeleteMapping(value = "returnPayment")
    public HttpResult returnPayment(@RequestParam(value = "id",defaultValue = "")String id){
        partyDfService.returnPayment(id);

        return HttpResult.ok("退回成功");
    }

    @Log(title = "导出年度党费记录表-Excel")
    @ApiOperation(value = "导出年度党费记录表-Excel")
    @GetMapping(value = "exportYearDfDataExcel")
    public void exportYearDfDataExcel(@RequestParam(value = "year",defaultValue = "")String year, HttpServletResponse response){
        partyDfService.exportYearDfDataExcel(year, response);
    }


}
